/*
 * SyncApplication.java
 *
 * Created on April 12, 2007, 1:34 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.app.admin;

import org.atomojo.app.App;
import org.atomojo.app.db.DB;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.routing.Filter;
import org.restlet.routing.Router;

/**
 *
 * @author alex
 */
public class UserApplication extends Application
{
   
   DB db;
   /** Creates a new instance of SyncApplication */
   public UserApplication(Context context,DB db)
   {
      super(context);
      this.db = db;
      getTunnelService().setEnabled(false);
   }
   
   @Override
   public Restlet createRoot() {
      Router router = new Router(getContext());
      router.attach("/",UsersResource.class);
      router.attach("/{alias}",UserResource.class);
      router.attach("/{alias}/{facet}",UserResource.class);
      router.attach("/{alias}/{facet}/",UserResource.class);
      router.attach("/{alias}/{facet}/{facet-alias}",UserResource.class);
      Filter dbFilter = new Filter(getContext()) {
         protected int beforeHandle(Request request,Response response)
         {
            request.getAttributes().put(App.DB_ATTR,db);
            return Filter.CONTINUE;
         }
      };
      dbFilter.setNext(router);
      return dbFilter;
      
   }
}
